package sample;

import java.awt.*;

public class SimpleLayout extends LayoutAdapter {

    @Override
    public void removeLayoutComponent(Component comp) {

    }

    @Override
    public void layoutContainer(Container parent) {
        System.out.println("使用了布局管理器");
        int width = parent.getWidth();
        int height = parent.getHeight();
        Component[] children = parent.getComponents();//子控件

        int x = 0;
        int y = 0;
        for (int i = 0; i < children.length; i++) {
            Component c = children[i];
            c.setBounds(x, y, 100, 100);
            x += 100;
            if (x > width) {
                x = 0;
                y += 100;
            }
        }
    }

    @Override
    public void addLayoutComponent(Component comp, Object constraints) {

    }
}
